
//获取输入框
var inputs = document.querySelectorAll('input');
//获取登陆按钮
var loginBtn = document.querySelector('button');

//给登录按钮 绑定点击事件
loginBtn.onclick = ()=>{
    //发起登陆请求
    axios.post('/user/login', { phone:inputs[0].value, pass:inputs[1].value} ).then((res)=>{
        if(res.data.code == 200){

            //将token存储到了localStorage中
            localStorage.setItem('token',res.data.token)
            //将服务器返回的用户信息，存储到了localStorage中
            localStorage.setItem('userinfo',JSON.stringify(res.data.userinfo))

            alert('登陆成功！')
            location.href = './index.html'
        }else{
            alert('登陆失败！')
        }
    })
}

